const HtmlWebpackPlugin = require('html-webpack-plugin')
const path = require('path')



const config = {
    mode: 'development',
    entry: {
        index: path.resolve(__dirname, './src/js/index.js'),
        list: path.resolve(__dirname, './src/js/list.js')
    },
    output: {
        path: path.resolve(__dirname + '/dist'),
        filename: 'js/[name].js'
    },
    module: {
        rules: [
            {
                test: /\.(woff2?|eot|ttf|oft|svg)(\?.*)?$/i,
                loader: [
                    'url-loader?name=fonts/[name].[ext]'
                ]
            },
            {
                test: /\.css$/i,
                use: [
                    "style-loader",
                    "css-loader"
                ]

            },
            {
                test: /\.s[ac]ss$/i,
                use: [
                    "style-loader",
                    "css-loader",
                    "sass-loader"
                ]
            },
            {
                test: /\.tpl$/,
                loader: 'ejs-loader',
                options: {
                    variable: 'data',
                    // interpolate: '\\{\\{(.+?)\\}\\}',
                    // evaluate: '\\[\\[(.+?)\\]\\]'
                }
            }
        ]

    },
    plugins: [
        new HtmlWebpackPlugin({
            minify: {
                removeComments: true,
                collapseWhitespace: true
            },
            filename: 'index.html',
            template: path.resolve(__dirname, 'src/index.html'),
            title: '腾讯课堂首页',
            chunksSortMode: 'manual',
            chunks: ['index'],
            excludeChunks: ['node_modules'],
            hash: true
        }),
        new HtmlWebpackPlugin({
            minify: {
                removeComments: true,
                collapseWhitespace: true
            },
            filename: 'index.html',
            template: path.resolve(__dirname, 'src/list.html'),
            title: '腾讯课堂首页-list',
            chunksSortMode: 'manual',
            chunks: ['index'],
            excludeChunks: ['node_modules'],
            hash: true
        })
    ],

    devServer: {
        watchOptions: {
            ignore: /node_modules/
        },
        hot: true,
        open: true,
        host: 'localhost',
        contentBase: path.resolve(__dirname, './src'),
        port: 8080
    }
}

module.exports = config